// 清除所有帖子的回复
export const clearAllReplies = () => {
  try {
    // 清除所有可能存储回复的localStorage项
    localStorage.removeItem('postReplies');
    localStorage.removeItem('comments');
    localStorage.removeItem('replies');
    
    // 清除帖子中的回复计数
    let posts = JSON.parse(localStorage.getItem('posts') || '[]');
    posts = posts.map(post => ({
      ...post,
      replies: 0
    }));
    localStorage.setItem('posts', JSON.stringify(posts));
    
    // 清除笔记中的回复计数
    let notes = JSON.parse(localStorage.getItem('notes') || '[]');
    notes = notes.map(note => ({
      ...note,
      comments: 0
    }));
    localStorage.setItem('notes', JSON.stringify(notes));
    
    console.log('所有帖子回复已成功清除');
    return true;
  } catch (error) {
    console.error('清除帖子回复时出错:', error);
    return false;
  }
};

// 初始化时自动执行清除
document.addEventListener('DOMContentLoaded', () => {
  // 只有在开发环境或需要时才自动清除
  if (process.env.NODE_ENV === 'development') {
    clearAllReplies();
  }
});